package org.rslai.tcedit.business.impl;

import java.util.List;
import org.rslai.tcedit.business.CatalogService;
import org.rslai.tcedit.domain.Catalog;
import org.rslai.tcedit.exception.ApplicationException;

/**
 * CatalogService 接口的实现<br/>
 * 注意: <tx:annotation-driven /> 这些方法已支持事务
 * 
 * @author rslai
 * 
 * @spring.bean id="catalogService"
 */
public class CatalogServiceImpl  extends AbstractBaseService implements CatalogService {

	public void delete(Catalog catalog) {
		throw new IllegalArgumentException("请调用带productID参数的delete方法: " + Catalog.class.getName());
	}

	public void delete(String productID, Catalog catalog) {
		if (catalogDao.countCatalog(productID, catalog.getId())!=0 || testCaseDao.countTestCase(productID, catalog.getId())!=0) {
			throw new ApplicationException("删除分类失败，此分类下存在子分类或用例！");
		}
		catalogDao.delete(catalog);
	}

	public List<Catalog> queryCatalog(String productID, String versionID, String parentCatalogID, boolean asc) {
		return catalogDao.query(productID, versionID, parentCatalogID, asc);
	}

	public Long countCatalog(String productID, String catalogID) {
		return catalogDao.countCatalog(productID, catalogID);
	}

}
